package com.fizzkai.p2p;

import com.fizzkai.p2p.mgrsite.filter.MyFilter;
import com.fizzkai.p2p.mgrsite.interceptor.CheckLoginInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@SpringBootApplication
@EnableScheduling
public class MgrSiteApp extends WebMvcConfigurerAdapter{

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(checkLoginInterceptor()).addPathPatterns("/*").excludePathPatterns("/mgrLogin");
    }

    @Bean
    public CheckLoginInterceptor checkLoginInterceptor(){
        return new CheckLoginInterceptor();
    }

//    @Bean
//    public MappedInterceptor allInterceptor(CheckLoginInterceptor tem){
//        return new MappedInterceptor(new String[]{"/*"}, tem);
//    }

    @Bean
    public FilterRegistrationBean testFilterBean() {
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(new MyFilter());
        bean.addUrlPatterns("/*");
        return bean;

    }

    public static void main(String[] args) {
        SpringApplication.run(MgrSiteApp.class, args);
    }
}
